package com.day0913;

import java.util.Arrays;
import java.util.Scanner;

public class Text3_4_2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        //数组的增删改(默认从数组最后操作)
        String[] phones = {"iphone1","iphone2","iphone3","iphone4"};
        //数组的增加
        //复制一个新数组
        String[] new_phones = Arrays.copyOf(phones,phones.length + 1);
        //新数组赋值
        for (int i = 0; i < phones.length; i ++) {
            new_phones[i] = phones[i];
        }
        System.out.println("请输入添加的值：");
        String last_phone = in.next();
        new_phones[phones.length] = last_phone;
        for (String phone : new_phones) {
            System.out.print(phone + " ");
        }
        System.out.println();
        //数组的删除
        String[] del_phones = Arrays.copyOf(phones,3);
        for (int i = 0; i < del_phones.length; i ++){
            del_phones[i] = phones[i];
        }
        for (String phone : del_phones) {
            System.out.print(phone + " ");
        }
        System.out.println();
        //数组的修改
        System.out.println("请输入要修改的值：");
        String revise_before = in.next();
        String revise_after;
        boolean flag = true;
        for (int i = 0; i < phones.length; i ++){
            if (!phones[i].equals(revise_before)){
                flag = false;
                continue;
            }
            else {
                System.out.println("找到了，请输入修改后的值：");
                revise_after = in.next();
                phones[i] = revise_after;
                flag = true;
                break;
            }
        }
        if (flag == false){
            System.out.println("抱歉，没有找到你要修改的值！");
        }
        for (String phone : phones) {
            System.out.print(phone + " ");
        }

    }
}
